package com.framework
{
	import flash.events.*;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.utils.*;
	import flash.xml.*;

	public class GameDataController
	{
		public var Loader:URLLoader;
		public var xmlData:XML;
		public var _URL:String;
		public var xmlDataURL:URLRequest;
		public var xmlLoader:URLLoader;
				
		public var stage_id:int;
		public var level_id:int;
		
		//����Ϸ��INFO����û�н�ȫ��ʱ�����ñ��ഫ��һЩʵʱ����Ϸ����
		public var totalEnemies:int;
		public var killedEnemies:int;
		//����Ϸ��INFO����û�н�ȫ��ʱ�����ñ��ഫ��һЩʵʱ����Ϸ����
		
		public var LevelInfoArray:Array;
		
		private static var instance:GameDataController;
		private static var key:Boolean;
		
		public function GameDataController()
		{
			LevelInfoArray = new Array;
			if(!key)
			{
				throw new Error("This is a Singleton. Use getInstance instead")
			}
		}
		
		public static function getInstance():GameDataController
		{
			if(instance == null)
			{
				key = true;
				instance = new GameDataController
			}
			return instance;
		}
		
		public function loadDataFile(file:String):void
		{
			Loader = new URLLoader();
			xmlData = new XML();
			_URL = file;
			xmlDataURL = new URLRequest(_URL);
		//	trace(xmlDataURL);
			xmlLoader = new URLLoader(xmlDataURL);
			loadXML();
		}
		
		public function loadXML():void
		{
			xmlLoader.addEventListener(Event.COMPLETE, onLoaded);
		}
		
		public function onLoaded(e:Event):void 
		{
			xmlData = XML(xmlLoader.data);
			loadStageInfo();
			trace(xmlData);
		}
		
		public function loadStageInfo():void
		{
			for(var k:int = 0;k<xmlData.my_stage.length();k++)
			{
				var temp:int = xmlData.my_stage.(@id == k+1).my_level.length();
				GameDataController.getInstance().LevelInfoArray.push(temp);
			}
		}
		
		public function getMousePos(x,y):void
		{
		//	mouse_x = x;
		//	mouse_y = y;
			
		}
	}
}